<?php
namespace Admin\Controller;

class SettingController extends CommonController
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 查看系统变量
     * @return [type]
     */
    public function index()
    {
        $setting = setting([
            'shop_new_goods_expire',
            'shop_new_goods_limit',
            'red_voice_match_percent',
            'goods_cache_expire',
        ]);
        $this->assign('setting', $setting);

        $this->assign('bread_crumb', $bread_crumb = generate_bread_crumb([
            '系统设置',
            '系统配置',
        ]));
        $this->display();
    }

    /**
     * 更新setting值
     * @return [type] [description]
     */
    public function update()
    {
        $items = I('post.', []);
        if (count($items)) {
            foreach ($items as $key => $value) {
                setting($key, $value, false);
            }
            setting_clean();
        }

        $this->success('更新成功');

    }

    /**
     * 清空新品缓存
     * @return [type] [description]
     */
    public function cleanNewGoods()
    {
        $max_shop = M('shop')->max('id');
        for ($i = 0; $i < $max_shop; $i++) {
            S('shop_new_goods_' . $i, null);
        }
        $this->success('缓存已清除');
    }

    /**
     * 清除权限缓存
     * @return [type] [description]
     */
    public function cleanRules()
    {
        S('rules', null);
        $this->success('权限缓存已清除');
    }
}
